﻿// ===============================================================================
// DaoInterfaceGenerator.cs
// EOS Framework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Data.Generator
{
    using System.CodeDom;
    using System.Reflection;
    using System.Globalization;
    using EOS.Framework.Tools.Aspects;

    /// <summary>
    /// Responsible for creating dao interfaces.
    /// </summary>
    public class DaoInterfaceGenerator : BaseGenerator
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DaoInterfaceGenerator"/> class.
        /// </summary>
        /// <param name="targetNamespace">The target namespace.</param>
        /// <param name="className">Name of the class, where this interface is created for.</param>
        /// <param name="tableName">Name of the table, which is handled by the dao.</param>
        [ParamNotNullOrEmpty("targetNamespace"), ParamNotEmpty("className"), ParamNotEmpty("tableName")]
        public DaoInterfaceGenerator(string targetNamespace, string className, string tableName)
            : base(targetNamespace)
        {
            CodeTypeDeclaration daoInterfaceDeclaration = new CodeTypeDeclaration("I" + className + "Dao");
            daoInterfaceDeclaration.IsInterface = true;
            daoInterfaceDeclaration.IsPartial = true;
            daoInterfaceDeclaration.BaseTypes.Add(new CodeTypeReference("EOS.Framework.Data.IBaseDao", new CodeTypeReference(className)));

            daoInterfaceDeclaration.Comments.Add(new CodeCommentStatement("<summary>", true));
            daoInterfaceDeclaration.Comments.Add(new CodeCommentStatement(string.Format(CultureInfo.CurrentCulture, "DAO Interface for the table '{0}'", tableName), true));
            daoInterfaceDeclaration.Comments.Add(new CodeCommentStatement("</summary>", true));

            TargetNamespace.Types.Add(daoInterfaceDeclaration);
        }
    }
}
